//============================================================================
// Name        : Found.cpp
// Author      : Anthea Neums, Jonas Halbach
//			   :
// Description : This Class Found is used to
//				 store the positions where the pattern and the genom match.
//============================================================================

#include "Found.h"



namespace algorithm {

using namespace std;

Found::Found(int genomPosition, int patternPosition, int matchingLength, char *string) {
	this->genomPosition = genomPosition;
	this->patternPosition = patternPosition;
	this->matchingLength = matchingLength;
	this->string = string;
}


//Getter and Setter
int Found::getGenomPosition()
{
	return genomPosition;
}

void Found::setGenomPosition(int genomPosition)
{
	this->genomPosition = genomPosition;
}

int Found::getPatternPosition()
{
	return patternPosition;
}

void Found::setPatternPosition(int patternPosition)
{
	this->patternPosition = patternPosition;
}

int Found::getMatchingLength()
{
	return matchingLength;
}

void Found::setMatchingLength(int matchingLength)
{
	this -> matchingLength = matchingLength;
}

void Found::setString(char *string)
{
	this->string = string;
}

char *Found::getString()
{
	return string;
}


//Print a found. Mainly for debugging issues.
void Found::print()
{
	cout << "\tPosition " << genomPosition <<": \t" << string << ";\t Pattern-Position: " << patternPosition << endl;
}


//Comparing operators
bool Found::operator == (const Found *found)
{
	return genomPosition == found->genomPosition &&
			patternPosition == found->patternPosition &&
			matchingLength == found-> matchingLength &&
			strcmp(string, found->string) == 0;
}

bool Found::operator != (const Found *found)
{
	return genomPosition != found->genomPosition ||
			patternPosition != found->patternPosition ||
			matchingLength != found-> matchingLength ||
			strcmp(string, found->string) != 0;
}

bool Found::operator == (const Found found)
{
	return genomPosition == found.genomPosition &&
			patternPosition == found.patternPosition &&
			matchingLength == found. matchingLength &&
			strcmp(string, found.string) == 0;
}

bool Found::operator != (const Found found)
{
	return genomPosition != found.genomPosition ||
			patternPosition != found.patternPosition ||
			matchingLength != found. matchingLength ||
			strcmp(string, found.string) != 0;
}


/**
 * This Method prooves if the pattern and the genom are matching over the specified bounds.
 * @param genomPosition 	: one Position of the genom, where the pattern and the genom match
 * @param patternPosition 	: one Position in the pattern, where genom and Pattern match.
 * @param n 				: is the minimal length of matching chars in the genom and pattern.
 * @return					: An pointer to a Found-object which stores the information about the
 * 								founded match.
 */
bool Found::contains(Found *newFound) {

	//Testing if the lower startposition of the genom of actFound is smaller than the	//startposition of the genom of an old Found
	bool genomlowerBorder = newFound->getGenomPosition()
			>= this->getGenomPosition();
	//Testing if the endposition of the actFound is greater than the endposition
	//bounds of an old Found
	bool patternlowerBorder = newFound->getPatternPosition()
			>= this->getPatternPosition();

	//Testing if the lower startposition of the pattern of actFound is smaller than the
	//startposition of the pattern of an old Found
	bool genomupperBorder = newFound->getGenomPosition()
			+ newFound->getMatchingLength()
			<= this->getGenomPosition() + this->getMatchingLength();

	//Testing if the endposition of the pattern of actFound is greater than the endposition
	//of the pattern of an old Found
	bool patternupperBorder = newFound->getPatternPosition()
			+ newFound->getMatchingLength()
			<= this->getPatternPosition() + this->getMatchingLength();

	return genomlowerBorder && patternlowerBorder && genomupperBorder
			&& patternupperBorder;
}


Found::~Found() {
}

} /* namespace algorithm */
